package LeetCode;

import java.util.Arrays;

/**
 * @author VX5
 * @Title: MJC
 * @ProjectName DataStructure
 * @Description: TODO
 * @date ${DAT}22:03
 */
public class interview62 {

    public static void main(String[] args) {
        int[] nums = {0,0,1,2,5};
        System.out.println(new interview62().isStraight(nums));
    }

    public boolean isStraight(int[] nums) {
        int inAble = 0;
        Arrays.sort(nums);
        for (int i = 0; i < nums.length; i++){
            if (nums[i] == 0){
                inAble++;
            }
            if (i > 0 && nums[i] != nums[i-1]+1 && nums[i - 1] != 0 && nums[i] != 0){
                inAble -= nums[i] - nums[i-1] - 1;
                if (inAble < 0){
                    return false;
                }
            }
            if (i > 0 && nums[i] == nums[i-1] && nums[i] != 0){//有對子
                return false;
            }
        }
        return true;
    }
}
